<?php
/* Skinmanager plugin for Textcube 1.5
   ----------------------------------
   Version 1.0
   Tatter and Company development team.

   Creator          : skk97

   Created at       : 2007.04.09
   Last modified at : 2007.04.09
 
 This plugin manages Skin files on administration menu.
 For the detail, visit http://www.tattertools.com/ko/bbs/view.php?id=skinnotice&no=1 (korean)


 General Public License
 http://www.gnu.org/licenses/gpl.html

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

*/

if(isset($__ts)) unset($__ts);
$__ts = array();

global $blog, $service, $__ts;
# Locale language file support, defualt is en-us.php
if (!isset($blog['blogLanguage'])) {
	$blog['blogLanguage'] = $service['language'];
}
// Locale language file support.
switch($blog['blogLanguage']) {
	case "zh-TW":
	case "zh-CN":
		$languageFile = 'lang/'.$blog['blogLanguage'].'.php';
	break;
	default:
		$languageFile = "";
}
if(!empty($languageFile)) { include ($languageFile); }

function TT_SkinManagerInit()
{
	global $blogid, $pluginMenuURL, $pluginURL, $pluginSelfParam,$blog, $user,$blogURL,$defaultURL, $hostURL,$service,$skinSetting,$__ts;
	requireComponent( "Textcube.Model.Statistics");
	requireComponent( "Textcube.Model.Paging");
	requireComponent( "Textcube.Function.misc");
	require_once ('lang/pluginLocal.php');
	
	$skin_name  = $skinSetting['skin'];
	$mode = !empty($_POST['mode'])?$_POST['mode']:"";
	$skinname = !empty($_POST['skin'])?$_POST['skin']:"";
	$skinfolder = !empty($_POST['skinfolder'])?$_POST['skinfolder']:"";
	$page = !empty($_GET['page'])?$_GET['page']:"1";
	$sort = !empty($_GET['sort'])?$_GET['sort']:"time";
	$skin_category = !empty($_GET['category'])?$_GET['category']:"";
	include"common/lib.php";
	if(TT_confirmHost($useMember) == false){
		return ;
	} 
	if($mode == "ttskin"){
			$incfile = "common/ttskin.php";
			$titlename = pluginLang::plts('텍스트큐브 공개스킨');
			$mySkinClass = NULL;
			$tatterSkinClass = 'selected';
			$classname = "tatterSide";
	}else{ 
			$incfile = "common/files.php";
			$titlename = pluginLang::plts('내 스킨 파일');
			$mySkinClass = 'selected';
			$tatterSkinClass = NULL;
			$classname = "mySide";
			if($skinfolder !="")
				$classname = "webFtp";
	}

	$curdir = $start.$skinfolder;
	$javascript = pluginLang::pllang2javascript();
?>
<?php echo $javascript; ?>
<script type="text/javascript" src="<?php echo $pluginURL;?>/js/TT_SkinManager.js"></script>
<form name="reg" style="margin:0" method="post" action="<?php echo $pluginMenuURL;?>">
	<input type="hidden" name="skin" value="<?php echo $skin_name;?>" />
	<input type="hidden" name="mode" value="<?php echo $mode;?>" />
	<input type="hidden" name="skinfolder" value="<?php echo $skinfolder;?>" />
		<div id="part-skin" class="part">
			<h2 class="caption"><span class="main-text"><?php echo pluginLang::plts('스킨 폴더');?></span></h2>
				<div class="part-skinBox">
					<h3><?php echo pluginLang::plts('현재 적용중인 스킨');?></h3>
					<div class="mySkinImage"><a href="<?php echo $hostURL.$blogURL;?>"><img src="<?php echo $service['path'];?>/skin/<?php echo $skin_name;?>/preview.gif" alt="preview" /></a></div>
					<span class="mySkinTitle"><?php echo $skin_name;?></span>
					<h3><?php echo pluginLang::plts('내 스킨 폴더');?></h3>
					<ul class="mySkinList">
<?php
				echo '<li><a href="'.$pluginMenuURL.'"><strong>'.pluginLang::plts('전체보기').'</strong></a></li>';
				$total_folder = TT_SkinManagerGetSkins($start,0,0, $curdir,$skinname);
?>
						<li class="makeFolder">
						<input type="text" class="input-text" name="new_dir" onKeyDown="if(event.keyCode == 13){return js_confirm();}" /><input type="button" class="btn" value="<?php echo pluginLang::plts('스킨추가');?>" onclick="return js_confirm();">
						</li>
					</ul>
				<a href='#void' onclick='openPopup("<?php echo $blogURL;?>/plugin/TT_SkinManagerHelp/", 600, 500, "_help", "scrollbars=1");' class="helpIcon"><?php echo pluginLang::plts('스킨매니저 도움말 보기');?></a>
			</div>
		</div>
		<div id="part-skin-folder" class="<?php echo $classname;?>">
			<h2 class="caption"><span class="main-text"><?php echo $titlename;?></span></h2>
			<ul class="tabs-box">
				<li class="mySkin <?php echo $mySkinClass;?>"><a href="<?php echo $pluginMenuURL;?>"><span><?php echo pluginLang::plts('내 스킨 폴더 목록');?></span></a></li>
				<li class="tatterSkin <?php echo $tatterSkinClass;?>"><a href="<?php echo $pluginMenuURL;?>&amp;mode=ttskin"><span><?php echo pluginLang::plts('태터툴즈 스킨 가져오기');?></span></a></li>
			</ul>
			<?php include $incfile;?>	
		</div><!-- part-skin-folder end-->						
</form>
<div id=popuplayer style="display:none;position:absolute;"></div>
<div class="clear"></div>
<script type="text/javascript">
	//<![CDATA[
	window.addEventListener("load", execLoadFunction, false);
	function execLoadFunction() {
		total = document.images.length;
		for(i=0;i <total;i++){
			obj = document.images[i];
			if(obj.className == "img_preview"){
				fit_img(obj,120,120);
			}
		}
	}
	//]]>
</script>
<?php
}

function TT_SkinManagerUpload($target){
	global $service,$blogURL, $database, $defaultURL,$blogid,$pluginURL,$hostURL;
	require_once ('lang/pluginLocal.php');
	if(doesHaveOwnership())
		require_once "/common/flashupload.php";
	return $target;
}

function TT_SkinManagerUpload2($target){
	global $service,$blogURL, $database, $defaultURL,$blogid,$pluginURL,$hostURL;
	require_once ('lang/pluginLocal.php');
	if(doesHaveOwnership())
		require_once "common/fileupload.php";
	return $target;
}

function TT_SkinManagerEdit($target){
	global $service,$blogURL, $database, $defaultURL,$blogid,$pluginURL,$hostURL;
	require_once ('lang/pluginLocal.php');
	if(doesHaveOwnership())
		require_once "common/edit.php";
	return $target;
}

function TT_SkinManagerExec($target){
	global $service,$blogURL, $database, $defaultURL,$blogid,$pluginURL,$hostURL;
	require_once ('lang/pluginLocal.php');
	if(doesHaveOwnership())
		require_once "common/exec.php";
	return $target;
}

function TT_SkinManagerFileupload($target){
	global $service,$blogURL, $database, $defaultURL,$blogid,$pluginURL,$hostURL;
	require_once ('lang/pluginLocal.php');
	if(doesHaveOwnership())
		require_once "common/upload.php";
	return $target;
}

function TT_SkinManagerHelp($target){
	global $service,$blogURL, $database, $adminSkinSetting, $defaultURL,$blogid,$pluginURL,$hostURL;
	require_once ('lang/pluginLocal.php');
	if(doesHaveOwnership())
		require_once "common/help.php";
	return $target;
}

function TT_SkinManagerGet($target){
	global $service,$blogURL, $database, $defaultURL,$blogid,$pluginURL,$hostURL;
	require_once ('lang/pluginLocal.php');
	if(doesHaveOwnership())
		require_once "common/ttskinget.php";
	return $target;
}

function TT_SkinManagerInfo($target){
	global $service,$blogURL, $database, $defaultURL,$blogid,$pluginURL,$hostURL;
	require_once ('lang/pluginLocal.php');
	if(doesHaveOwnership())
		require_once "common/ttskininfo.php";
	return $target;
}

if( !function_exists('doesHaveOwnership')){
	function doesHaveOwnership(){
		global $blogid;
		if(empty($_SESSION['userid'])||($_SESSION['userid']!=$blogid))
			return false;
		return true;
	}
}
?>
